package com.kh.chart;

import com.kh.domain.ChannelData;

import java.util.ArrayList;
import java.util.List;

public class DataHelper {

    private final static int DEVICE_COUNT = 1;
    private final static int CHANNEL_COUNT = 1;
    private final static int VALUE_COUNT = 1600 * 4 * 3;

    /**
     * 模拟设备的通道数据
     * @return
     */
    public static List<ChannelData> createChannelDatas() {
        List<ChannelData> dataList = new ArrayList<>();
        for (int i = 0; i < DEVICE_COUNT; i++) {
            for (int j = 0; j < CHANNEL_COUNT; j++) {
                ChannelData channelData = new ChannelData();
                int deviceId = i + 1;
                channelData.setDeviceId(deviceId);
                channelData.setDeviceName(getDeviceName(deviceId));
                int channelNo = j + 1;
                channelData.setChannelNo(channelNo);
                channelData.setChannelDesc(getChannelDesc(channelNo));
                channelData.setValues(getChannelValues());
                dataList.add(channelData);
            }
        }
        return dataList;
    }

    private static String getDeviceName(int deviceId) {
        return (new StringBuilder()).append("设备").append(deviceId).toString();
    }

    private static String getChannelDesc(int channelNo) {
        switch (channelNo) {
            case 1:
                return "导体Ia";
            case 2:
                return "导体Ib";
            case 3:
                return "导体Ic";
            case 4:
                return "护套Ia";
            case 5:
                return "护套Ib";
            case 6:
                return "护套Ic";
            case 7:
                return "接地电流I0";
            default:
                return "未知";
        }
    }

    private static List<Double> getChannelValues() {
        List<Double> values = new ArrayList<>();
        for (int i = 0; i < VALUE_COUNT; i++) {
            values.add(Math.random() * 100.0);
        }
        return values;
    }
}
